package cn.edu.nju.freshdelivery.action.seller;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import cn.edu.nju.freshdelivery.constant.Result;
import cn.edu.nju.freshdelivery.model.Seller;
import cn.edu.nju.freshdelivery.service.impl.SellerServiceImpl;

import com.opensymphony.xwork2.ActionSupport;

@Component
public class SellerRegisterAction extends ActionSupport {
	private Seller seller;
	private SellerServiceImpl sellerService;
	private String result;

	public Seller getSeller() {
		return seller;
	}

	public void setSeller(Seller seller) {
		this.seller = seller;
	}

	/*
	 * public SellerServiceImpl getSellerService() { return sellerService; }
	 */
	@Resource
	public void setSellerService(SellerServiceImpl sellerService) {
		this.sellerService = sellerService;
	}

	public String getResult() {
		return result;
	}

	public void setResult(String result) {
		this.result = result;
	}

	@Override
	public String execute() throws Exception {
		/**
		 * TODO:服务器端验证合法性
		 */
		result = SUCCESS;
		//用户名已被注册
		if (sellerService.findByUsername(seller.getUsername()) == null)
			result = Result.EXISTED;
		sellerService.add(seller);
		return SUCCESS;
	}
}
